FROM eclipse-temurin:17-jdk AS build

WORKDIR /app

# Copy gradle files for dependency resolution
COPY build.gradle settings.gradle gradlew ./
COPY gradle ./gradle

# Download dependencies (cached if no changes)
RUN ./gradlew dependencies

# Copy source code
COPY src ./src

# Build the application
RUN ./gradlew build

# Runtime image
FROM eclipse-temurin:17-jre

WORKDIR /app

# Copy the jar from the build stage
COPY --from=build /app/build/libs/*.jar /app/app.jar

# Expose ports
EXPOSE 502 102 1883

# Set environment variables (can be overridden at runtime)
ENV MODBUS_PORT=502
ENV S7_PORT=102
ENV MQTT_BROKER_HOST=localhost
ENV MQTT_BROKER_PORT=1883
ENV MQTT_ENABLE_COMPRESSION=true

# Run the application
ENTRYPOINT ["java", "-jar", "/app/app.jar"] 